package io.kiki.stack.http.feign.form.multipart;

import feign.codec.EncodeException;
import io.kiki.stack.http.feign.form.FormData;
import lombok.val;

/**
 * A {@link FormData} writer.
 *
 * @author Guillaume Simard
 * @since 24.03.2018
 */
public class FormDataWriter extends AbstractWriter {

    @Override
    public boolean isApplicable(Object value) {
        return value instanceof FormData;
    }

    @Override
    protected void write(Output output, String key, Object value) throws EncodeException {
        val formData = (FormData) value;
        writeFileMetadata(output, key, formData.getFileName(), formData.getContentType());
        output.write(formData.getData());
    }
}
